﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using EraNet.Core;
using EraNet.Data;
using EraNet.Core.Model.Account;
using EraNet.Core.Model.SysManage;

using EraNet.Common;
using EraNet.Services.Account;
using EraNet.Services.Drivings;
using EraNet.Services.Test;
using EraNet.Services.SysManage;
using EraNet.WebApp.AppCore;

namespace EraNet.WebApp.IMS
{
    public class TestController : IMSBasePage
    {
        #region Fields
        private readonly IExaminationService _examinationService;
        private readonly ISysCardsService _syscardsService;
        private readonly IDriveSchoolService _driveschoolService;
        private readonly IDictionaryService _dictionaryService;
        private readonly ISysConfigService _sysconfigService;
        private readonly IMemberService _memberService;
        private readonly IStudyLocusService _studyLocusService;
        #endregion

        #region Constructors
        public TestController(IExaminationService examinationService, IDictionaryService dictionaryService, ISysConfigService sysconfigService, ISysCardsService syscardsService, IDriveSchoolService driveschoolService,
            IMemberService memberService, IStudyLocusService studyLocusService)
        {
            this._examinationService = examinationService;
            this._syscardsService = syscardsService;
            this._dictionaryService = dictionaryService;
            this._sysconfigService = sysconfigService;
            this._driveschoolService = driveschoolService;
            this._memberService = memberService;
            this._studyLocusService = studyLocusService;
        }
        #endregion

        #region Method
        #region
        public ActionResult CertExamInfo(int? page)
        {
            ViewBag.myTabId = "1";
            if (page == null) page = 1;
            page = page - 1;
            #region 获取当前用户信息，根据当前用户信息取考试信息
            Employee m = _driveschoolService.GetLoginClient();
            var list= _examinationService.GetExamLogsBySchool(m.SchoolID, (int)page, 20);
            //var list = _examinationService.GetExamLogsBySchool(0, (int)page, 1);
            #endregion
            return View(list);
        }
        #endregion

        #region 培训详情

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">用户id</param>
        /// <param name="page">页索引</param>
        /// <param name="menuType">科目类型：1→科目一、2→科目二、3→科目三</param>
        /// <returns></returns>
        public ActionResult BackVideoStudyDetail(int id, int? page, string menuType)
        {
            ViewBag.myTabId = "1";
            int pageIndex = page ?? 1;
            pageIndex -= 1;
            int pageSize = 1;
            if (string.IsNullOrEmpty(menuType))
            {
                menuType = "1";
            }
            //根据学员id获取登录学员
            Member student = _memberService.GetMemberById(id);
            if (student == null)
            {
                return RedirectToAction("Index", "Account");
            }
            //各个科目
            List<SelectListItem> items=new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "科目一", Value = "1" });
            items.Add(new SelectListItem() { Text = "科目二", Value = "2" });
            items.Add(new SelectListItem() { Text = "科目三", Value = "3" });

            ViewBag.MenuTypes = new SelectList(items,"Value","Text", menuType);

            ViewBag.userName = student.Names;
            ViewBag.userId = student.Id;
            ViewBag.menuType = menuType;
            var list = _studyLocusService.GetVMList(student.Id, pageIndex, pageSize, menuType);

            return View(list);
        }

        #endregion

        #endregion
    }
}
